package holdobject;

import typeinfo.pets.Hamster;
import typeinfo.pets.Pet;
import typeinfo.pets.Pets;
import typeinfo.pets.Rat;

import java.util.LinkedList;

import static net.mindview.util.Print.print;

public class LinkedListFeatures {
    public static void main(String[] args) {
        LinkedList<Pet> pets=new LinkedList<Pet>(Pets.arrayList(5));
        print(pets);
        //
        print("pets.getFirst:"+pets.getFirst());
        print("pets.element:"+pets.element());//列表为空时有异常
        print("pets.peek:"+pets.peek());//列表为空时返回null
        //
        print("pets.remove:"+pets.remove());//移除并返回列表的头，空时有异常
        print("pets.removeFirst:"+pets.removeFirst());
        print("pets.poll:"+pets.poll());//删除此列表的头，列表空时返回null
        print(pets);//此时列表里只剩两个元素
        pets.addFirst(new Rat());
        print("After addFirst()"+pets);
        pets.offer(Pets.randomPet());//在尾部随机插入一个
        print("After offer"+pets);
        pets.add(Pets.randomPet());
        print("After add"+pets);
        pets.addLast(new Hamster());
        print("After addLast"+pets);
        print(pets.removeLast());
        print(pets);
    }

}
